function bindData(rowData){
	var unemployedId = rowData.unemployedId;
	$('#unemployedId').val(unemployedId);
	
	if(rowData.knry!='1'){
		$('#addAidEffectButton').linkbutton('disable');
		$('#updateAidEffectButton').linkbutton('disable');
		$('#delAidEffectButton').linkbutton('disable');
	} else if(rowData.knry=='1'){
		$('#addAidEffectButton').linkbutton('enable');
		$('#updateAidEffectButton').linkbutton('enable');
		$('#delAidEffectButton').linkbutton('enable');	
	}
	
    $('#aidEffectGrid').datagrid({ 
    	url:'jobless/difficultyServer/getAidEffectGridList',  
        idField:'id',
        queryParams:{
        	unemployedId:unemployedId
	    },
        rownumbers:true,
        fit:true,
        fitColumns:true,
        singleSelect:true,
        pagination:true,
        columns:[[
                  {field:'id',hidden:'true'}, 
                  {field:'unemployedId',hidden:'true'},
                  {field:'employdate',title:'就业时间',width:100,align:'center',
                	     formatter:function(data){ 
                	    	 if(data!=null){
                	    		 var df = new Date(data);  
                                 return df.format("yyyy-MM-dd");       			   
       		                 } else{
       		        	         return null;
       		                 }
       	                 }},  
                  {field:'assistant',title:'就业协理员',width:100,align:'center'},
                  {field:'companytype',title:'单位性质',width:100,align:'center'},
                  {field:'company',title:'工作单位',width:100,align:'center'},                 
                  {field:'post',title:'工作岗位',width:100,align:'center'},
                  {field:'salary',title:'月薪待遇',width:100,align:'center'},
                  {field:'satisfaction',title:'工作满意度',width:100,align:'center'},
                  {field:'competence',title:'对工作的胜任程度',width:120,align:'center'},
                  {field:'opinion',title:'意见和建议',width:100,align:'center'},
                  {field:'client',title:'援助对象签字',width:100,align:'center'},                 
                  {field:'staff',title:'工作人员签字',width:100,align:'center'}
                ]]    	
    }); 
}

$("#addAidEffect").window({
	onClose:function(data){
		$('#addAidEffectForm').form('clear');
	}  		      
});

function addAidEffect(){
	var curr_time = new Date();
	var strDate = curr_time.getFullYear()+"-"+(curr_time.getMonth()+1)+"-"+curr_time.getDate();
	$('#aidEffectAdd_employdate').datebox('setValue',strDate);	
	$('#addAidEffect').window('open');
}

/**
 * 添加困难人员跟踪服务记录
 */
function insertAidEffect(){
	$('#addAidEffectForm').form('submit',{
		url:'jobless/difficultyServer/insertAidEffect',
		queryParams:{
			unemployedId: $('#unemployedId').val()
		},
		success: function(data){
			data =  $.parseJSON(data);
			if(data.success == 'true'){
				$.messager.alert('提示','保存成功','info');
				$('#addAidEffect').window('close');
				$('#addAidEffectForm').form('clear');
				$('#aidEffectGrid').datagrid('reload');
			}else{
				$.messager.alert('提示',data.message,'info');
			}
		}
	});
}

/**
 * 删除一条添加困难人员跟踪服务记录
 * 
 */
function delAidEffect(){
	var rowData = $('#aidEffectGrid').datagrid('getSelected');
	if(rowData == undefined){
		$.messager.alert('消息','请选择一条数据');
	}else{
		$.messager.confirm('提示','确定要删除吗？',function(r){
			if(r){
				$.ajax({
					url:'jobless/difficultyServer/deleteAidEffect',
					type:'post',
					data:{
						id:rowData.id
					},
					success:function(data){
						data =  $.parseJSON(data);
						if(data.success == 'true'){
							$.messager.alert('提示','删除成功','info');
							$('#aidEffectGrid').datagrid('load');
							$('#aidEffectGrid').datagrid('unselectAll');
						}else{
							$.messager.alert('提示',data.message,'info');
						}
					}
				});
			}
		});
	}
}

/**
 * 回显一条困难人员就业援助记录
 * 
 */
function getAidEffect(){
	var rowData = $('#aidEffectGrid').datagrid('getSelected');
	if(rowData == undefined){
		$.messager.alert('消息','请选择一条数据');
	}else{
		$('#modifyAidEffect').window('open');
		//alert(rowData.id);
		$.ajax({
			url:'jobless/difficultyServer/getAidEffectInfo',
			type:'post',
			data:{
				id:rowData.id
			},
			success: function (data) {
				if(data==null){
					$('#modifyAidEffectForm').form('clear');
				}else{
					$('#modifyAidEffectForm').form('load',data);
				}
	        },
	        error:function(data){
	        	$('#modifyAidEffectForm').form('clear');
	        }
		});
	}
}

/**
 * 修改一条困难人员就业援助记录
 * 
 */
function modifyAidEffect(){
	var modifyFlag = $('#modifyAidRecordForm').form('validate');
	if(modifyFlag==false){
		$.messager.alert('提示','表单填写不正确');
		return;
	}else{
		$.ajax({
			url:'jobless/difficultyServer/updateAidEffect',
			type:'post',
	        async: false,
	        data:$('#modifyAidEffectForm').serialize(),
	        success:function(data){
	        	data =  $.parseJSON(data);
		        if(data.success == 'true'){
		        	$.messager.alert('提示','保存成功','info');
			        $('#modifyAidEffect').window('close');
			        $('#modifyAidEffectForm').form('clear');
			        $('#aidEffectGrid').datagrid('reload');
					$('#aidEffectGrid').datagrid('unselectAll');
		        }else{
		        	$.messager.alert('提示',data.message,'info');

		        }
	        },
	        error:function(data){
	        	alert("ajax发生错误！");	
	        }
        });
	}	
}

/**
 * 日期格式化
 * @param value
 * @param row
 * @returns {String}
 */
function formatterDate(value) {
    var date = new Date(value);
    return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
}

function parserDate(s){
	var t = Date.parse(s);
	if (!isNaN(t)){
		return new Date(t);
	} else {
		return new Date("1975-08-01");
	}
	
	
}